package com.example.forum.utils;

import com.example.forum.domain.User;
import org.springframework.stereotype.Component;

/*
    存储用户信息,用来代替session
 */
@Component
public class HostHolder {
    private ThreadLocal<User> local=new ThreadLocal<>();

    public void setUser(User user){
        local.set(user);
    }

    public User getUser(){
        User user = local.get();
        return user;
    }

    public void clear(){
        local.remove();
    }
}
